﻿
@{
    ViewBag.Title = "ConfigGuidance";
    Layout = "~/Views/Shared/layoutCommon.cshtml";
}

@section style{
    <style>
        .col-sm-2 {
            width: 20%;
            float: left;
            text-align: right;
            margin-top: 5px;
        }

        .col-sm-3 {
            width: 30%;
            float: left;
        }
    </style>
}
<form id="form1">
    <section class="content-header">
        <h1>
            @ViewBag.CityName 配置业务
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
            <li><a href="@Url.Content("~/config/CityOpenManage")?provinceid=@ViewBag.ProvinceId">省市业务开通</a></li>
            <li><a href="@Url.Content("~/config/FormBusiness")?cityid=@ViewBag.CityId&provinceid=@ViewBag.ProvinceId&cityname=@ViewBag.CityName">配置业务</a></li>
            <li class="active">配置表单</li>
        </ol>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header">
                        <div class="bs-example">
                            <ul class="nav nav-tabs">
                                <li role="presentation"><a href="@Url.Content("~/Config/ConfigForm?provinceid="+@ViewBag.ProvinceId+"&cityname="+@ViewBag.CityName+"&cgfid="+@ViewBag.CgfId+"")">配置表单</a></li>
                                <li role="presentation"><a href="@Url.Content("~/Config/ConfigPrice?provinceid="+@ViewBag.ProvinceId+"&cityname="+@ViewBag.CityName+"&cgfid="+@ViewBag.CgfId+"")">配置价格</a></li>
                                <li role="presentation"><a href="@Url.Content("~/Config/ConfigOrderExpire?provinceid="+@ViewBag.ProvinceId+"&cityname="+@ViewBag.CityName+"&cgfid="+@ViewBag.CgfId+"")"> 网办订单过期</a></li>
                                <li role="presentation" class="active"><a href="#">配置说明</a></li>
                                <li role="presentation"><a href="@Url.Content("~/Config/ConfigExpressTemplate?provinceid="+@ViewBag.ProvinceId+"&cityname="+@ViewBag.CityName+"&cgfid="+@ViewBag.CgfId+"")">配置快递</a></li>
                                <li role="presentation"><a href="@Url.Content("~/Config/ConfigView?provinceid="+@ViewBag.ProvinceId+"&cityname="+@ViewBag.CityName+"&cgfid="+@ViewBag.CgfId+"")">配置预览</a></li>
                            </ul>
                        </div>

                        <h3>
                            <i class="fa fa-fw fa-arrow-right"></i>@ViewBag.BizTypeName
                        </h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="form-horizontal">
                        <div class="box-body">
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="name">内容:</label>
                                <div class="col-sm-3">
                                    <textarea id="txtGuidance" name="txtGuidance" class="ueditor-80p" style="width:800px; height:250px;"></textarea>
                                    <input type="hidden" id="hidGuidance" value="" name="hidGuidance" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-footer text-center">
                        <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                        <button class="btn" type="button" id="btnCancel">取 消 </button>
                    </div>
                    <!-- /.box-body -->
                    <!-- /.box -->
                </div>
            </div>
        </div>
    </section>
</form>
@section scriptsBottom{
    <script src="@Url.Content("~/ueditor/ueditor.config.js")"></script>
    <script src="@Url.Content("~/ueditor/ueditor.all.min.js")"></script>
    <script src="@Url.Content("~/ueditor/lang/zh-cn/zh-cn.js")"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            renderUeditor();
            $("#btnSave").click(function () {
                save();
            });
            $("#btnCancel").click(function () {
                cancel();
            });
        });

        //保存
        function save()
        {

            if (UE.getEditor('txtGuidance').getContent()=="") {
                BMCW.alert("内容不能为空!");
                return;
            }
            var url = '@Url.Action("SaveGuidance", "Config")'
            BMCW.ajax({
                url: url,
                type: "Post",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                data: {
                    CityID: @ViewBag.CityId,
                    BizTypeID: @ViewBag.BizTypeId,
                    GuidanceHtml: ajax_encode(UE.getEditor('txtGuidance').getContent()),
                    GuidanceWxMini: UE.getEditor('txtGuidance').getPlainTxt()
                },
                success: function (o) {
                    if (o.status == 0) {
                        BMCW.msg("保存成功",function(){
                            BMCW.getTopSelectedWin().search();
                        });
                    } else {
                        BMCW.alert("保存失败");
                    }
                }
            });

        }

        //取消，跳回上一页面
        function cancel()
        {
            history.go(-1);
        }

        //初始化数据
        function renderUeditor() {
            BMCW.ajax({
                url: '@Url.Content("~/Config/GetGuidanceInfo")?cityId=@ViewBag.CityId&bizTypeId=@ViewBag.BizTypeId',
                type: "Get",
                success: function (o) {
                    if (o.status == 0) {
                        if (o.data!=null) {
                            UE.getEditor("txtGuidance").ready(function () {
                                this.setContent(o.data.GuidanceHtml);
                            });
                        }

                    }
                }

            });
            
        }

        function ajax_encode(str) {
            str = str.replace(/%/g, "{$bai$}");
            str = str.replace(/ /g, "{$kong$}");
            str = str.replace(/</g, "{$zuojian$}");
            str = str.replace(/>/g, "{$youjian$}");
            str = str.replace(/&/g, "{$and$}");
            str = str.replace(/\"/g, "{$shuang$}");
            str = str.replace(/\'/g, "{$dan$}");
            str = str.replace(/\t/g, "{$tab$}");
            str = str.replace(/\+/g, "{$jia$}");
            return str;
        }
    </script>
}
